unit untDlgPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ActnList, cxPropertiesStore, cxContainer, cxEdit,
  cxClasses, cxStyles, cxGridTableView, cxLookAndFeels,
  cxGridCustomPopupMenu, cxGridPopupMenu, ImgList, cxGraphics, DB,
  IBCustomDataSet, dxBarDBNav, dxBar, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxDBData, cxGridLevel, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridDBTableView, cxGrid, cxPC, Menus,
  cxLookAndFeelPainters, StdCtrls, cxButtons, cxProgressBar, cxGroupBox,
  dxmdaset, IBQuery,cxStorage, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmDlgPadrao = class(TForm)
    cxImageList1: TcxImageList;
    cxPropertiesStore: TcxPropertiesStore;
    ActionList1: TActionList;
    ActFechar: TAction;
    dtList: TIBQuery;
    dsRegistro: TDataSource;
    pgcCadastro: TcxPageControl;
    tbsLista: TcxTabSheet;
    tbsEdita: TcxTabSheet;
    Panel2: TPanel;
    frmTreePadrao: TPanel;
    ActOK: TAction;
    ActCancelar: TAction;
    cxGroupBox1: TcxGroupBox;
    btnOK: TcxButton;
    btnCancelar: TcxButton;
    PB: TcxProgressBar;
    mtbFiltro: TdxMemData;
    dsFiltro: TDataSource;
    lstParametro: TIBQuery;
    lstParametroCODIGO: TIntegerField;
    lstParametroUSUARIO: TIntegerField;
    lstParametroDATA_MOVTO: TDateField;
    lstParametroOPERACAO: TIntegerField;
    lstParametroPRODUTOR: TIntegerField;
    lstParametroTERCEIRO: TIntegerField;
    lstParametroPROPRIEDADE: TIntegerField;
    lstParametroPRODUTO: TIntegerField;
    lstParametroANO_BASE: TIntegerField;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure lstParametroBeforeOpen(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
    codigo : integer;
  end;

var
  frmDlgPadrao: TfrmDlgPadrao;

implementation

uses untDmPrincipal;

{$R *.dfm}

procedure TfrmDlgPadrao.FormCreate(Sender: TObject);
var
  FMyStream: TMemoryStream;
  DirUser, Diretorio : String;
begin
  cxPropertiesStore.StorageName := TfrmDlgPadrao(Sender).Name;
  cxPropertiesStore.StorageType := stStream;
  FmyStream := TMemoryStream.Create;
  cxPropertiesStore.StorageStream := FMyStream;
  DirUser := GetEnvironmentVariable('USERPROFILE');
  // Later I load the Stream from database
  if FileExists(DirUser+'\'+cxPropertiesStore.StorageName) then
  begin
    FMyStream.LoadFromFile(DirUser+'\'+cxPropertiesStore.StorageName);
    FMyStream.Position := 0;
    cxPropertiesStore.RestoreFrom;
  end;


  mtbFiltro.Open;
  mtbFiltro.Append;
end;

procedure TfrmDlgPadrao.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
  Diretorio :string;
  DirUser : String;
begin
   DirUser := GetEnvironmentVariable('USERPROFILE');
          (cxPropertiesStore.StorageStream as TMemoryStream).Position := 0;
           cxPropertiesStore.StoreTo(true);
          (cxPropertiesStore.StorageStream as TMemoryStream).SaveToFile((DirUser+'\'+cxPropertiesStore.StorageName));

end;

procedure TfrmDlgPadrao.FormShow(Sender: TObject);
begin
  lstParametro.Close;
  lstParametro.Open;
end;

procedure TfrmDlgPadrao.lstParametroBeforeOpen(DataSet: TDataSet);
begin
  lstParametro.ParamByName('usuario').value := dmPrincipal.usuario_logado_codigo;
end;

end.
